<template></template>
<script setup lang="ts">
	import {watch, ref, computed, createVNode} from 'vue'
	import {ExclamationCircleOutlined} from '@ant-design/icons-vue'
	import {Modal, message} from 'ant-design-vue'
	import {deleteEmergency} from '@/api/contract'
	import {sexList} from '@/utils'

	const props = defineProps({
		visible: {
			type: Boolean,
			required: true
		},
		id: {
			type: [String, Number],
			required: true
		}
	})
	const emit = defineEmits(['update:visible', 'success'])
	const cancel = () => {
		emit('update:visible', false)
	}
	watch(
		() => props.visible,
		(newVal: boolean) => {
			if (newVal) {
				Modal.confirm({
					title: '删除紧急联系人',
					icon: createVNode(ExclamationCircleOutlined),
					content: `确认删除当前紧急联系人信息？`,
					onOk() {
						return deleteEmergency(props.id)
							.then((res: any) => {
								message.success('操作成功')
								setTimeout(() => {
									emit('success')
								}, 300)
							})
							.finally(() => {
								cancel()
							})
					},
					onCancel() {
						cancel()
					}
				})
			}
		}
	)
</script>
<style lang="less"></style>
